<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CustomAction
 *
 * @author Administrator
 */
import('@.Filter.SecurityAction');
import("@.ORG.Net.Keditor");
import('@.Service.CustomService');
import('ORG.Util.Page');

class CustomAction extends SecurityAction {

    function custom() {
        $customService = new CustomService();
        $count = $customService->count();

        $page = new Page($count, 10);

        $show = $page->show();
        $list = $customService->listCustom($page->firstRow . ',' . $page->listRows);


        $this->assign('show', $show);
        $this->assign('list', $list);

        $this->assign('content', 'custom');
        $this->display('Admin:global');
    }

    function customAboutme() {

        $ke = new Keditor();
        $ke->id = "custom_text"; //指定textarea的id
        $ke->form = "frm_custom"; //指定form的id，默认为from1
        $ke->afterCreate = "ctrlenter"; //定义创建后执行函数，ctrlenter表示ctrl+enter提交表单。
        $keshow = $ke->show(); //生成js代码
        $this->assign("keshow", $keshow);

        $id = $_REQUEST['id'];
        if (!empty($id)) {
            $customService = new CustomService();
            $custom = $customService->findCustomById($id);

            $this->assign('custom', $custom);
        }

        $this->assign('content', 'custom_aboutme');
        $this->display('Admin:global');
    }

    function customAboutmeSave() {
        $customService = new CustomService();
        $custom = $customService->create();
        $id = $_POST['id'];
        if (empty($id)) {
            $id = $customService->insert($custom);
            $custom['id'] = $id;
            $custom['url'] = __APP__ . '/Index/custom/id/' . $id . '.shtml';
            $customService->update($custom);
        } else {
            $customService->update($custom);
        }

        $this->assign('custom_text', $custom['content']);

        $this->assign('content', 'Index:custom');
        $this->buildHtml("Custom/" . $id, '', 'Index:global');

        $this->redirect('custom');
    }

    function customAboutmeDelete() {
        $customService = new CustomService();
        $id = $_POST['id'];

        if (file_exists(APP_PATH . '/Html/Custom/' . $id . '.shtml')) {
            unlink(APP_PATH . '/Html/Custom/' . $id . '.shtml');
        }

        $customService->delete($id);

        $this->redirect('custom');
    }

}

?>
